﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IFRS.Web;
using System.Data;
using IFRS.DataAccess.DAL;

public partial class IFRS_SEC01_3A : PageBase
{
   
    #region "---------- Events -----------"
    protected void Page_Load(object sender, EventArgs e)
    {
        
        if (!(Page.IsPostBack || Page.IsCallback))
        {
            this.ViewMenu();
            SetErrorMessage();
        }
        else
            ClientScript.RegisterHiddenField("isPostBack", "1");
    }
    protected void btnSAVE_Click(object sender, EventArgs e)
    {
        SaveData(false);
    }
    protected void btnSAVE_NEW_Click(object sender, EventArgs e)
    {
        SaveData(true);
    }
    protected void btnCANCEL_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/IFRS/SEC01_1S.aspx");
    }
    protected void btnCLEAR_Click(object sender, EventArgs e)
    {
        Response.Redirect(ResolveUrl(Request.Url.AbsoluteUri));
    }
    #endregion
    #region "----- Methods -------"
    private void ViewMenu()
    {
        this.MenuTitleBar = Resources.ifrsMenu.SEC01_1S;
    }
    private void SetErrorMessage()
    {
        btnSAVE.ValidationGroup = "Master";
        reqROLE_GROUP_NAME.SetRequiredField(lblROLE_GROUP_NAME, txtROLE_GROUP_NAME, btnSAVE);
    }

    private void SaveData(bool SaveNew)
    {

        try
        {
            bool AllBranch;
            bool IsActive;
            if (cbJOB.Checked)
            {
                AllBranch = true;
            }
            else 
            {
                AllBranch = false;
            }
             if (rbSTATUS_1.Checked)
            {
                IsActive = true;
            }
            else 
            {
                IsActive = false;
            }
            var vROLEGROUP = new ROLEGROUP();
            int iID = vROLEGROUP.INSERT(txtROLE_GROUP_NAME.Text, AllBranch, IsActive, DateTime.Now, SessionManager.IFRS_EMPLOYEE_ID, 
                                        SessionManager.IFRS_COST_CENTER, SessionManager.IFRS_BRANCH, DateTime.Now, SessionManager.IFRS_EMPLOYEE_ID, 
                                        SessionManager.IFRS_COST_CENTER, SessionManager.IFRS_BRANCH);
            if (iID > 0)
            {

                if (SaveNew)
                {
                    this.JS_Alert(Resources.ifrsResource.SaveData, ResolveUrl("~/IFRS/SEC01_3A.aspx"));
                }
                else
                {
                    this.JS_Alert(Resources.ifrsResource.SaveData, ResolveUrl(string.Format("~/IFRS/SEC01_2E.aspx?&id={0}", iID)));
                }
            }
            else
            {
                if (iID == -1)
                {
                    Utility.AlertMessage(Page, Resources.ifrsResource.Duplicate);
                }
                else
                {
                     Utility.AlertMessage(Page, Resources.ifrsResource.CanNotSaveData);
                }
               
            }

        }
        catch (Exception ex)
        {
            throw ex;
        }

    }
    #endregion
 
}